package ai.leinao.monitor.configuration;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;


/**
 * @author yjb
 * @create 2025/11/5 18:00
 */
@Configuration
public class SecurityConfiguration {

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        http.authorizeExchange(exchanges -> // 设置权限配置
                        exchanges
                                .pathMatchers("/actuator/**").permitAll()
                                .pathMatchers("/assets/**").permitAll() // 静态资源，允许匿名访问
                                .pathMatchers("/login").permitAll() // 登录接口，允许匿名访问
                                .anyExchange().authenticated() //
                )
                .formLogin().loginPage("/login") // 登录页面
                .and().logout().logoutUrl("/logout") // 登出界面
                .and().httpBasic() // HTTP Basic 认证方式
                .and().csrf().disable(); // csrf 禁用
        return http.build();
    }
}
